package cn.fff.system.controller;

import cn.fff.common.result.Result;
import cn.fff.model.system.SysMenu;
import cn.fff.system.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/menu")
@Api(tags = "菜单管理接口")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("菜单列表查询")
    @GetMapping("findNodes")
    public Result<List<SysMenu>> findNodes() {
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.ok(list);
    }

    @ApiOperation("添加菜单")
    @PostMapping("save")
    public Result<Void> saveMenuNode(@RequestBody SysMenu sysMenu) {
        return sysMenuService.save(sysMenu) ? Result.ok() : Result.fail();
    }

    @ApiOperation("根据id查询菜单")
    @GetMapping("findNode/{id}")
    public Result<SysMenu> findNodeById(@PathVariable String id) {
        return Result.ok(sysMenuService.getById(id));
    }

    @ApiOperation("修改菜单")
    @PostMapping("update")
    public Result<Void> updateById(@RequestBody SysMenu sysMenu) {
        return sysMenuService.updateById(sysMenu) ? Result.ok() : Result.fail();
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("remove/{id}")
    public Result<Void> remove(@PathVariable String id) {
        sysMenuService.removeMenuById(id);
        return Result.ok();
    }

}
